package com.wwm.springcloud.authservice.common;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

/**
 * SDK工具类
* @ClassName: ToolUtils 
* @author wwm
* @date 2017年4月17日 上午9:30:59 
*
 */
public class ToolUtils
{
	public static boolean isNull(Object obj)
	{
		boolean isNullFlag = true;
		if (obj != null)
			if (obj instanceof List)
				isNullFlag = isNull((List) obj);
			else if (obj instanceof Set)
				isNullFlag = isNull((Set) obj);
			else if (obj instanceof Object[])
				isNullFlag = isNull((Object[]) (Object[]) obj);
			else if (obj instanceof Map)
				isNullFlag = isNull((Map) obj);
			else if (obj instanceof String)
				isNullFlag = isNull((String) obj);
			else
				isNullFlag = false;

		return isNullFlag;
	}

	public static boolean isNull(List<?> list)
	{
		return ((list == null) || (list.size() == 0));
	}

	public static boolean isNull(Set<?> set)
	{
		return ((set == null) || (set.size() == 0));
	}

	public static boolean isNull(Object[] objects)
	{
		return ((objects == null) || (objects.length == 0));
	}

	public static boolean isNull(Map<?, ?> map)
	{
		return ((map == null) || (map.isEmpty()));
	}

	public static boolean isNull(String str)
	{
		return ((str == null) || ("".equals(str.trim())) || ("null".equalsIgnoreCase(str.trim())));
	}

	public static String formatNull(Object str)
	{
		return (isNull(str)?"":str.toString());
	}

	public static String getUUID()
	{
		return UUID.randomUUID().toString().replaceAll("-", "");
	}

	/**
	 * 获取时间差-防止科学计数法
	 * @param begintime 毫微秒System.nanoTime()
	 * @param endtime 毫微秒
	 * @return
	 */
	public static String getTimeInterval(long endtime,long begintime)
	{
		double hs = ((double)(endtime - begintime))/1000000000;
		BigDecimal bigDecimal = new BigDecimal(hs);
		return bigDecimal.setScale(20,BigDecimal.ROUND_HALF_UP).toString();
	}
}
